/**
 * sms_to_email_ym
 * Constants.java
 * 2012-3-7 2012
 * A sms to email tools. 
 * Copyright (c) Joyo8 app lab
 * Author: a.w@qq.com
 */

/**
 * @author root
 *
 */

package com.joyo8.app;

import android.os.Environment;
import android.util.Log;

import java.io.File;

public class Constants {

    public static final String TAG = "smst";

    public static final String PRE_NAME = "com.aw.app";

    public static final String PRE_SENDER = "sender";

    public static final String PRE_PASSWORD = "password";

    public static final String PRE_RECEIVER = "receiver";

    public static final String PRE_NUMBERS = "numbers";

    public static final String PRE_DEF_VALUE = "";

    public static final String INTENT_SMS = "android.provider.Telephony.SMS_RECEIVED";

    public static final int MSG_SEND_MAIL = 1;

    public static final int MSG_SAVE_FILE = 2;
    
    public static final int MSG_SEND_FILE = 3;

    public static final String APP_FOLDER = Environment.getExternalStorageDirectory() + "/smst/";

    public static final String SAVE_FILE = "log.txt";

    public static void logd(String msg) {
        Log.d(TAG, msg);
    }

    public static void createSMSFile() {
        File f = new File(Constants.APP_FOLDER);
        if (!f.exists()) {
            Constants.logd(Constants.APP_FOLDER + " not exist, will create it");
            try {
                if (f.mkdirs()) {
                    Constants.logd(Constants.APP_FOLDER + " folder create successful");
                    File file = new File(Constants.APP_FOLDER + Constants.SAVE_FILE);
                    if (!file.exists()) {
                        // create log file
                        if (file.createNewFile()) {
                            Constants.logd(Constants.APP_FOLDER + Constants.SAVE_FILE
                                    + " create successful");
                        } else {
                            Constants.logd(Constants.APP_FOLDER + Constants.SAVE_FILE
                                    + " create failed");
                        }
                    }
                } else {
                    Constants.logd(Constants.APP_FOLDER + " folder create failed");
                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                Constants.logd(e.getMessage());
                e.printStackTrace();
            }
        } else {
            Constants.logd(Constants.APP_FOLDER + " exists.");
            File file = new File(Constants.APP_FOLDER + Constants.SAVE_FILE);
            if (!file.exists()) {
                // create log file
                try {
                    if (file.createNewFile()) {
                        Constants.logd(Constants.APP_FOLDER + Constants.SAVE_FILE
                                + " create successful");
                    } else {
                        Constants.logd(Constants.APP_FOLDER + Constants.SAVE_FILE
                                + " create failed");
                    }
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    Constants.logd(e.getMessage());
                    e.printStackTrace();
                }
            }
        }
    }
}
